from pandac.PandaModules import *
from direct.interval.MetaInterval import *
from direct.interval.IntervalGlobal import *

from AudioMgr import audio
from globals import *
    
##def delExplosion(explode):
##    explode.removeNode()
##    del explode

def playExplosion(position, size, damage=None):
    startscale = size / 4
    m = loader.loadModel(DATAPATH+'sphere')

    if damage:
        damage.addPandaBody(m, 'boom', CollisionSphere(0,0,0, startscale))

    m.setTransparency(TransparencyAttrib.MAlpha)
    m.setScale(startscale, startscale, startscale)
    m.setPos(position)
    m.reparentTo(render)

    # make large explosions last longer than small ones
    duration = size * 0.75

    # scale interval
    Sequence( m.scaleInterval(duration, Vec3(size, size, size)) ).start()
    # color interval
    m.setColor(1.0, 1.0, 0.2,1)
    Sequence(m.colorInterval(duration, VBase4(0.6,0.1,0.0,0.0)),
             Func( m.removeNode )).start()
            
